import { ref } from 'vue'
import { messageData } from '../upload/upload'
import router from '@/router/index'
export const studyData = () => {
  const studying = ref(false)
  const { information } = messageData()

  const join = () => {
   
    if (studying.value===false)
  {
    studying.value = true;
    information.incrementStudents()
  }
  }

  const study = () => {
    if (information.selectedOption === '免费') {
     
      join();
      console.log(information.viewNumber)
      
    } else {
      router.push('/buy')
    }
  }
 const  disstudy=()=>
  {
      information.deleteStudents()
      join();
  }

  const viewCourse=()=>
    {
      if (studying.value===true) {
       router.push('/course')
        information.viewNumber++;
        console.log(information.viewNumber)
        
      } else {
        alert('请先加入课程')
      }
    }
  return {
    studying,
    join,
    study,
    disstudy,
    viewCourse
  }
}